/**
 * 
 */
package utils;

/**
 * @author Michael
 *
 */
public class HelpUtils {

	public static <T> void swap(T[] arr, int i, int j) {

		if (arr == null || i == j || i < 0 || i >= arr.length || j < 0
				|| j >= arr.length) {
			return;
		}

		T temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
	}

	public static void swap(int[] arr, int i, int j) {

		if (arr == null || i == j || i < 0 || i >= arr.length || j < 0
				|| j >= arr.length) {
			return;
		}

		int temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
	}

	public static <T> void randomShuffle(T[] arr) {

		for (int i = arr.length - 1; i >= 0; --i) {
			int rand = (int) (Math.random() * (i + 1));
			swap(arr, i, rand);
		}
	}
}
